<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fnx" uri="http://java.sun.com/jsp/jstl/functionsx"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="f" uri="http://www.itcms.com/tags/form"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Itcms管理平台 - Powered by Itcms</title>
<jsp:include page="/WEB-INF/views/commons/head.jsp"></jsp:include>
</head>
<body class="c-body">
<jsp:include page="/WEB-INF/views/commons/show_message.jsp"/>

<script type="text/javascript">

$(function() {
	$("input:radio[name='maxSelected']").eq("${voteTitle.maxSelected}").attr("checked",true);
});

function addOptions(action){
	
	$('#saveAction').val(action);
	if(action == 'return'){
		$('#optionForm').submit();
	}else{
		$("#optionForm").validate({
			submitHandler: function(form) {
				form.submit();
			}
		});
	}	 
	$("input[name='name']").focus();
}

</script>
<c:set var="numberExist"><s:message code="vote.number.exist"/></c:set>
<div class="c-bar margin-top5">
  <span class="c-position"><s:message code="voteOption.management"/> - <s:message code="${oprt=='optionEdit' ? 'edit' : 'create'}"/></span>
</div>

 <form id="optionForm" title="<s:message code="createVoteOption"/>" action = "option.do"  method = "post" style="">
  <input type="hidden" name="voteTitleId" value="${voteTitle.id}"/>
  <input type="hidden" id="saveAction" name="saveAction" value=""/>
	<div class="inls-opt margin-top5">
	  <b><s:message code="vote.options"/></b> &nbsp;
	  <a href="javascript:void(0);" onclick="addOptionRow();" class="ls-opt"><s:message code='addRow'/></a> &nbsp;
	  <a href="javascript:void(0);" onclick="Cms.moveTop('ids');" class="ls-opt"><s:message code='moveTop'/></a>
	  <a href="javascript:void(0);" onclick="Cms.moveUp('ids');" class="ls-opt"><s:message code='moveUp'/></a>
	  <a href="javascript:void(0);" onclick="Cms.moveDown('ids');" class="ls-opt"><s:message code='moveDown'/></a>
	  <a href="javascript:void(0);" onclick="Cms.moveBottom('ids');" class="ls-opt"><s:message code='moveBottom'/></a>     
	</div>
	<textarea id="templateOptionArea" style="display:none">
		<tr>
	    <td align="center">
	    	<input type="checkbox" name="ids" value=""/>   	
	    	<input type="hidden" name="id" value=""/>   	
	    </td>
	    <td align="center">
	   	 <a href="javascript:void(0);" onclick="$(this).parent().parent().remove();" class="ls-opt"><s:message code="delete"/></a>
	   </td>
	    <td align="center"><f:text name="title" value="" class="required" maxlength="150" style="width:300px;"/></td>
	    <td align="center"><f:text name="count" value="0" class="{required:true,digits:true,min:0,max:2147483647}" maxlength="10" style="width:100px;text-align:right;"/></td>
	  </tr>
	</textarea>
	
<script type="text/javascript">
	var rowOptionIndex = 0;
	var rowOptionTemplate = $.format($("#templateOptionArea").val());
	function addOptionRow() {
		$(rowOptionTemplate(rowOptionIndex++)).appendTo("#optionTable tbody");
		$("#optionTable").tableHighlight();
	}
	$(function() {
		if(rowOptionIndex ==0) {
			<c:if test="${oprt=='optionSave'}">
			addOptionRow();
			</c:if>
		}
	});
</script>
<table id="optionTable" border="0" cellpadding="0" cellspacing="0" class="inls-tb">
  <thead>
  <tr>
    <th width="25"><input type="checkbox" onclick="Cms.check('ids',this.checked);"/></th>
    <th width="80"><s:message code="operate"/></th>
    <th><s:message code="voteItem.title"/></th>
    <th><s:message code="voteItem.total"/></th>
  </tr>
  </thead>
  <tbody>
  <c:forEach var="option" varStatus="status" items="${voteTitle.options}">
  <tr>
    <td align="center">
    	<input type="checkbox" name="ids"  value="${voteTitle.id}"/>
    	<input type="hidden" name="id" value="${option.id}"/>
    </td>
    <td align="center">
      <a href="javascript:void(0);" onclick="$(this).parent().parent().remove();" class="ls-opt"><s:message code="delete"/></a>
    </td>
    <td align="center"><f:text name="title" value="${option.title}" class="required" maxlength="150" style="width:300px;"/></td>
    <td align="center"><f:text name="count" value="${option.count}" class="{required:true,digits:true,min:0,max:2147483647}" maxlength="10" style="width:100px;text-align:right;"/></td>
  </tr>
  </c:forEach>
  </tbody>
</table>

<table border="0" cellpadding="0" cellspacing="0" class="in-tb margin-top5">
  <tr>
    <td class="in-lab" width="15%"><em class="required">*</em><s:message code="vote.multi"/>:</td>
    <td class="in-ctt" width="35%">
    
    	<label><f:radio name="maxSelected" value="0" checked=""/><s:message code="yes"/></label>
    	<label><f:radio name="maxSelected" value="1" checked="" default="1"/><s:message code="no"/></label>
		</td>
  </tr>
</table>
<div class="in-tb margin-top5">

      <div class="in-btn"><input type="submit" value="<s:message code="save"/>" onclick="addOptions('save');"/></div>
      <div class="in-btn"><input type="submit" value="<s:message code="saveAndReturn"/>" onclick="addOptions('saveAndReturn');"/></div>
      <div class="in-btn"><input type="submit" value="<s:message code="return"/>" onclick="addOptions('return');"/></div>
      <div style="clear:both;"></div>

</div>
</form>

</body>
</html>